package com.OneTest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.List;

public class ListTest {
    public static List readlist(){
        ObjectInputStream input=null;
        List list=null;
        try {
            input = new ObjectInputStream(new FileInputStream("./test.txt"));
            Object output = input.readObject();
            list=(List) output;

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (null!=input){
                try {
                    input.close();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

        return list;
    }

    public static void writelist(List list){
        ObjectOutputStream output=null;
        try {
            output=new ObjectOutputStream(new FileOutputStream("./test.txt"));
            output.writeObject(list);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (output!=null){
                try {
                    output.close();

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
        System.out.println("List :"+list);
        writelist(list);
        readlist();
    }
}
